<?php

namespace addons\sum\controller;

use app\admin\model\sum\Slideshows as SlideshowsModel;
use app\admin\model\sum\Slides as SlidesModel;

class Slides extends Common
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function index() 
    {
        $langSlug=$this->langSlug;
        $langOption=sum_config("language.option");// 语言选项
        $langDefaultSlug=$langOption[0]['slug'];// 默认语言
        $slug=$this->request->request('slug','home');
        $list_rows = $this->request->param('list_rows', 20);
        $records=SlidesModel::where('slug',$slug)->where('status','normal')->Order('weigh DESC')->where('lang',$langSlug)->paginate($list_rows);
        if($records->total()==0){// 如果目标语言数据为空，再次尝试默认语言
            $records=SlidesModel::where('slug',$slug)->where('status','normal')->Order('weigh DESC')->where('lang',$langDefaultSlug)->paginate($list_rows);
        }
        $this->success(__('Success'),$records);
    }
}
